﻿using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using WMS.DtoModels;

namespace Portal.Controllers
{
    public class OutportController : Controller
    {
        private readonly SqlSugarClient _sqlSugarClient;

        public OutportController(SqlSugarClient sqlSugarClient)
        {
            _sqlSugarClient = sqlSugarClient;
        }

        // GET
        public IActionResult LoadAllOutport(OutportInfoReqDto outportInfoReqDto)
        {
            var totalCount = 0;
            //var querySqlQueryable = this._sqlSugarClient.Context.Queryable<bus_outport>();
           
            var sql = $@"
select bo.*,bp.providername,bg.goodsname,bg.size from bus_outport as bo
left join bus_provider as bp on bo.providerId = bp.id
left join bus_goods as bg on bo.goodsid = bg.id
";

            var querySqlQueryable = this._sqlSugarClient.SqlQueryable<BusOutportViewModel>(sql);

            var queryResult = querySqlQueryable.ToPageList(outportInfoReqDto.Page, outportInfoReqDto.Limit, ref totalCount);

            var result = new
            {
                Code = 0,
                Msg = "查询成功",
                Count = totalCount,
                Data = queryResult
            };

            return Json(result);
        }
    }
}